#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <gmp.h>
#include <limits.h>
#include <time.h>

int main(void){
    unsigned long int i, num_pontos = 0;
    unsigned long int num_iteracoes = 99493984;
    time_t start, end;
    start = time(NULL);

    double x, y;
    mpf_t PI;
    mpf_t cont_points;
    mpf_t total;

    mpf_set_default_prec(10000000);
    mpf_init_set_ui(PI, 0L);
    mpf_init_set_ui(cont_points, 0L);
    mpf_init_set_ui(total, 0L);

    for(i = 0; i < num_iteracoes; i++) {
        x = drand48();
        y = drand48();
        if( pow((x*x + y*y),0.5) <= 1) num_pontos++;
    }

    mpf_set_si(cont_points, num_pontos);
    mpf_set_si(total, num_iteracoes);

    mpf_mul_ui(PI, cont_points, 4L);
    mpf_div(PI, PI, total);
    end = time(NULL);

    gmp_printf("%.10Ff", PI);

    return 0;
}





